import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class RedisDemoSet {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis = jedisPool.getResource()){
            //test1(jedis);
            //test2(jedis);
            //test3(jedis);
            //test4(jedis);
            test5(jedis);
        }
    }

    private static void test5(Jedis jedis) {
        System.out.println("sinter sinterstore");
        jedis.flushAll();
        jedis.sadd("key1", "111", "222", "333");
        jedis.sadd("key2", "111", "333", "444");
        Set<String> set1 = jedis.sinter("key1", "key2");
        System.out.println(set1);
        jedis.sinterstore("key3", "key1", "key2");
        Set<String> set2 = jedis.smembers("key3");
        System.out.println(set2);
    }

    private static void test4(Jedis jedis) {
        System.out.println("spop");
        jedis.flushAll();
        jedis.sadd("key1", "111", "222", "333");
        String result = jedis.spop("key1");
        System.out.println(result);
    }

    private static void test3(Jedis jedis) {
        System.out.println("scard");
        jedis.flushAll();
        jedis.sadd("key1", "111", "222", "333");
        long size = jedis.scard("key1");
        System.out.println(size);
    }

    private static void test2(Jedis jedis) {
        System.out.println("sismember");
        jedis.flushAll();
        jedis.sadd("key1", "111", "222", "333");
        boolean result = jedis.sismember("key1", "111");
        System.out.println(result);
    }

    private static void test1(Jedis jedis) {
        System.out.println("sadd smembers");
        jedis.flushAll();
        jedis.sadd("key1", "111", "222", "333");
        Set<String> set = jedis.smembers("key1");
        System.out.println(set);
    }
}
